import Tkinter as tk

from model import *
from view import *


class Controller:
    def __init__(self, root):
	print 'init controller'
        self.model = Model()
        self.model.myMoney.addCallback(self.MoneyChanged)
        self.model.myMoney.addCallback(self.LookAtThis)
        self.view1 = View(root)
        self.view1.check.config(command=self.MMoney)
        self.view2 = ChangerWidget(self.view1)
        self.view2.addButton.config(command=self.AddMoney)
        self.view2.removeButton.config(command=self.RemoveMoney)
        self.MoneyChanged(self.model.myMoney.get())

    def AddMoney(self):
        print 'addmoney controller'
        self.model.addMoney(10)

    def RemoveMoney(self):
        print 'removemoney controller'
        self.model.removeMoney(10)

    def MoneyChanged(self, money):
        print 'moneychanged controller'
        self.view1.SetMoney(money)

    def MMoney(self):
        self.model.mMoney()

    def LookAtThis(self, money):
        self.view1.SetMoney(money)


if __name__ == '__main__':
    root = tk.Tk()
    root.withdraw()
    app = Controller(root)
    root.mainloop()
